<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>注册页面</title>
    <link rel="stylesheet" href="css/register.css">
    <script src="js/jquery-3.6.0.js"></script>
    <link rel="stylesheet" href="font-awesome-4.7.0/css/font-awesome.css">
</head>
<!--else {
$.get(REGISTER_URL, param, function (result) {
if (result.status === 200) {
alert("注册成功")
location.href = "login.html"
} else if (result.status === -4) {
alert("注册失败")
}

})-->
<script>
    $(function () {
        const REGISTER_URL = "http://localhost:8080/insert/worker"
        $("#register").click(function () {
            let $worker_name = $("#worker_name").val();
            let $password = $("#password").val();
            let $rePassword = $("#passwordTest").val();
            let $watch_shop = $("#watch_shop").val();
            let $curd_shop = $("#curd_shop").val();
            let $worker_role = $("#worker_role").val();
            let $department = $("#department").val();
            let $job = $("#job").val();
            let $phone = $("#phone").val();
            let $email = $("#email").val();
            let $gender = $("#gender").val();
            let $id_number = $("#id_number").val();
            let $address = $("#address").val();
            let $detailed_address = $("#detailed_address").val();
            let param = {
                workerName: $worker_name,
                password: $password,
                watchShop: $watch_shop,
                curdShop: $curd_shop,
                workerRole: $worker_role,
                department: $department,
                job: $job,
                phone: $phone,
                tel: $("#tel").val(),
                email: $email,
                gender: $gender,
                idNumber: $id_number,
                address: $address,
                detailedAddress: $detailed_address,
                workerComment: $("#worker_comment").val()
            };
            let settings = {
                type: "POST",
                data: JSON.stringify(param),
                // 指定上传数据的类型  默认是  application/x-www-form-urlencoded
                contentType: "application/json",
                success: function (result) {
                    if (result.status === 200) {
                        alert("注册成功")
                        window.location.href = "login.html";
                    }
                },
                error: function (error) {
                    if (error.status === 404) {
                        alert("注册失败");
                    }
                }
            };
            if ($worker_name === null || $worker_name === "") {
                alert("姓名不能为空")
            } else if ($password === null || $password === "") {
                alert("密码不能为空")
            } else if ($rePassword === null || $rePassword === "") {
                alert("确认密码不能为空")
            } else if (!($password === $rePassword)) {
                alert("两次密码不一致")
            } else if ($watch_shop === null || $watch_shop === "") {
                alert("可看门店不能为空")
            } else if ($curd_shop === null || $curd_shop === "") {
                alert("操作门店不能为空")
            } else if ($worker_role === null || $worker_role === "") {
                alert("角色不能为空")
            } else if ($department === null || $department === "") {
                alert("部门不能为空")
            } else if ($job === null || $job === "") {
                alert("职务不能为空")
            } else if ($phone === null || $phone === "") {
                alert("电话不能为空")
            } else if ($email === null || $email === "") {
                alert("邮箱不能为空")
            } else if (($gender === null || $gender === "") && ($gender != "男" || $gender != "女")) {
                alert("性别不对")
            } else if ($id_number === null || $id_number === "") {
                alert("身份证不能为空")
            } else if ($address === null || $address === "") {
                alert("地址不能为空")
            } else if ($detailed_address === null || $detailed_address === "") {
                alert("详细地址不能为空")
            } else {
                $.ajax(REGISTER_URL, settings)
            }
        })
    })
</script>

<body style="background: url('images/BG1.jpg') ;background-repeat:no-repeat ;background-size:100% 100% ;background-attachment: fixed ;">
<div id="register-box">
    <h1>注 册</h1>
    <div class="form">
        <div class="item">
            <i class="fa fa-user" aria-hidden="true"></i>
            <label for="worker_name"></label>
            <input id="worker_name" type="text" placeholder="请输入姓名">
        </div>

        <div class="item">
            <i class="fa fa-key" aria-hidden="true"></i>
            <label for="password"></label>
            <input id="password" type="password" placeholder="请输入密码">
        </div>

        <div class="item">
            <i class="fa fa-key" aria-hidden="true"></i>
            <label for="passwordTest"></label>
            <input id="passwordTest" type="password" placeholder="请再次输入密码">
        </div>

        <div class="item">
            <i class="fa fa-key" aria-hidden="true"></i>
            <label for="watch_shop"></label>
            <input id="watch_shop" type="text" placeholder="请输入可看门店">
        </div>


        <div class="item">
            <i class="fa fa-key" aria-hidden="true"></i>
            <label for="curd_shop"></label>
            <input id="curd_shop" type="text" placeholder="请输入操作门店">
        </div>

        <div class="item">
            <i class="fa fa-key" aria-hidden="true"></i>
            <label for="worker_role"></label>
            <input id="worker_role" type="text" placeholder="请输入角色">
        </div>

        <div class="item">
            <i class="fa fa-key" aria-hidden="true"></i>
            <label for="department"></label>
            <input id="department" type="text" placeholder="请输入部门">
        </div>

        <div class="item">
            <i class="fa fa-key" aria-hidden="true"></i>
            <label for="job"></label>
            <input id="job" type="text" placeholder="请输入职务">
        </div>

        <div class="item">
            <i class="fa fa-key" aria-hidden="true"></i>
            <label for="phone"></label>
            <input id="phone" type="text" placeholder="请输入手机号">
        </div>

        <div class="item">
            <i class="fa fa-key" aria-hidden="true"></i>
            <label for="tel"></label>
            <input id="tel" type="text" placeholder="请输入电话">
        </div>

        <div class="item">
            <i class="fa fa-key" aria-hidden="true"></i>
            <label for="email"></label>
            <input id="email" type="text" placeholder="请输入邮箱">
        </div>

        <div class="item">
            <i class="fa fa-key" aria-hidden="true"></i>
            <label for="gender"></label>
            <input id="gender" type="text" placeholder="请输入性别">
        </div>

        <div class="item">
            <i class="fa fa-key" aria-hidden="true"></i>
            <label for="id_number"></label>
            <input id="id_number" type="text" placeholder="请输入身份证">
        </div>

        <div class="item">
            <i class="fa fa-key" aria-hidden="true"></i>
            <label for="address"></label>
            <input id="address" type="text" placeholder="请输入地址">
        </div>

        <div class="item">
            <i class="fa fa-key" aria-hidden="true"></i>
            <label for="detailed_address"></label>
            <input id="detailed_address" type="text" placeholder="请输入详细地址">
        </div>

        <div class="item">
            <i class="fa fa-key" aria-hidden="true"></i>
            <label for="worker_comment"></label>
            <input id="worker_comment" type="text" placeholder="备注">
        </div>

        <div class="item" style="color: whitesmoke">
            已经有了账户？<a href="login.html" class="txt2">立即登录</a>
        </div>
    </div>
    <button id="register">立 即 注 册</button>
</div>
</body>
</html>